home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + hash.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
- //------------------------------------------------------------------------------
- //
- // hash (data structure: hashing with chaining)
- //
- // Stefan Naeher (1989)
- //
- //------------------------------------------------------------------------------
-
- #ifndef HASHH
- #define HASHH
-
- #include <LEDA/ch_hashing.h>
-
- typedef ch_hashing_el* hash_item;
-
- #define hash(keytype,infotype) name3(keytype,infotype,hash)
-
- #define HFCT(keytype,infotype) name3(keytype,infotype,_hashfct)
-
- #define HFCTC(keytype,infotype) name3(keytype,infotype,_const_hashfct)
-
- #define hashdeclare2(keytype,infotype)\
- \
- typedef int (*HFCT(keytype,infotype))(keytype&);\
- typedef int (*HFCTC(keytype,infotype))(const keytype&);\
- \
- struct hash(keytype,infotype) : public ch_hashing {\
- \
- int cmp(ent& x, ent& y) const { return compare(*(keytype*)&x,*(keytype*)&y); }\
- void clear_key(ent& x) const { Clear(*(keytype*)&x); }\
- void clear_inf(ent& x) const { Clear(*(infotype*)&x); }\
- void copy_key(ent& x) const { Copy(*(keytype*)&x); }\
- void copy_inf(ent& x) const { Copy(*(infotype*)&x); }\
- void print_key(ent& x) const { Print(*(keytype*)&x); }\
- \
- int defined(keytype y) const { return ch_hashing::member(Ent(y)); }\
- hash_item lookup(keytype y) const { return ch_hashing::lookup(Ent(y)); }\
- void change_inf(hash_item it, infotype i)\
- { ch_hashing::change_inf(it,Ent(i)); }\
- hash_item insert(keytype y,infotype x)\
- { return ch_hashing::insert(Ent(y),Ent(x));}\
- void del(keytype y) { delete ch_hashing::del(Ent(y)); } \
- void del_item(hash_item it) { del(key(it)); } \
- keytype key(hash_item it) const { return keytype(ch_hashing::key(it)); }\
- infotype inf(hash_item it) const { return infotype(ch_hashing::inf(it)); } \
- infotype info(hash_item it) const { return infotype(ch_hashing::inf(it)); } \
- \
- hash(keytype,infotype)() {}\
- hash(keytype,infotype)(int s) :ch_hashing(s) {}\
- hash(keytype,infotype)(HFCT(keytype,infotype) f) :ch_hashing(hash_fct(f)) {}\
- hash(keytype,infotype)(HFCTC(keytype,infotype) f) :ch_hashing(hash_fct(f)) {}\
- hash(keytype,infotype)(int s, HFCT(keytype,infotype) f) :ch_hashing(s,hash_fct(f)) {}\
- hash(keytype,infotype)(int s, HFCTC(keytype,infotype) f) :ch_hashing(s,hash_fct(f)) {}\
- ~hash(keytype,infotype)() { remove(); }\
- } ;
-
-
- // ----------------------------------------------------------------
- // iteration
- // ----------------------------------------------------------------
-
- #define forall_hash_items(i,D) for((D).init_iterator(); i=(D).move_iterator();)
-
- #endif
-